#include "Box.h"
#include "Rectangle.h"
namespace RayTracer
{

	Box::Box(const vec3& p0, const vec3& p1, std::shared_ptr<Material> ptr)
	{
		box_min = p0; 
		box_max = p1; 

		sides.add(std::make_shared<XY_Rect>(p0.x, p1.x, p0.y, p1.y, p1.z, ptr));
		sides.add(std::make_shared<XY_Rect>(p0.x, p1.x, p0.y, p1.y, p0.z, ptr));
		sides.add(std::make_shared<XZ_Rect>(p0.x, p1.x, p0.z, p1.z, p1.y, ptr));
		sides.add(std::make_shared<XZ_Rect>(p0.x, p1.x, p0.z, p1.z, p0.y, ptr));
		sides.add(std::make_shared<YZ_Rect>(p0.y, p1.y, p0.z, p1.z, p1.x, ptr));
		sides.add(std::make_shared<YZ_Rect>(p0.y, p1.y, p0.z, p1.z, p0.x, ptr));
	}

	bool Box::Hit(const Ray& r, float t_min, float t_max, HitRecord& rec) const
	{
		return sides.Hit(r, t_min, t_max, rec);
	}

	bool Box::BoundingBox(AABB & output_box) const
	{
		output_box = AABB(box_min, box_max);
		return true;
	}
}